package com.sywb.chuangyebao.view.dialog;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sywb.chuangyebao.R;

import java.io.Serializable;

import butterknife.BindView;

public class VideoDetailIntroDialog extends BaseDialogFragment {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_intro)
    TextView tvIntro;

    private int contentHeight; // DialogActivity高度
    private String intro;

    public static VideoDetailIntroDialog newInstance(Object... pramars) {
        VideoDetailIntroDialog dialogFragment = new VideoDetailIntroDialog();
        Bundle bundle = new Bundle();
        if (pramars != null && pramars.length > 0) {
            for (int i = 0; i < pramars.length; i++) {
                bundle.putSerializable("p" + i, (Serializable) pramars[i]);
            }
        }
        dialogFragment.setArguments(bundle);
        return dialogFragment;
    }

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_video_detail_intro;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                exit();
            }
        });

        if (bundle != null) {
            contentHeight = bundle.getInt("p0", 0);
            intro = bundle.getString("p1");
        } else {
            contentHeight = getArguments().getInt("p0", 0);
            intro = getArguments().getString("p1");
        }

        tvTitle.setText("简介");
        tvIntro.setText(intro);
    }

    @Override
    public void onResume() {
        super.onResume();
        setWindowHeight();
    }

    private void setWindowHeight() {
        WindowManager.LayoutParams p = getDialog().getWindow().getAttributes();
        p.width = RelativeLayout.LayoutParams.MATCH_PARENT;
        if (contentHeight > 0) {
            p.height = contentHeight;
        } else {
            p.height = RelativeLayout.LayoutParams.MATCH_PARENT;
        }
        // p.gravity = Gravity.BOTTOM;
        // p.dimAmount = 0.8f;
        getDialog().getWindow().setAttributes(p);
    }


}
